package day11;

import java.util.Scanner;
import java.util.concurrent.locks.ReentrantLock;

public class Homework2 {
    static int count;
    static int num=0;
    ReentrantLock lock = new ReentrantLock(true);
    public void printA(){
        lock.lock();
        String name=Thread.currentThread().getName();
        if(count!=num){
            num++;
            System.out.println(name+":"+num);
        }
        lock.unlock();
    }

    public static void main(String[] args) {
        Homework2 h = new Homework2();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要计的数(整数)");
        count=sc.nextInt();
        while(count!=num){
            new Thread(()->{
                h.printA();
            },"计数器1").start();
            new Thread(()->{
                h.printA();
            },"计数器2").start();
            new Thread(()->{
                h.printA();
            },"计数器3").start();
        }
    }
}
